#include "DrawObject.h"
#include "DrawSystem.h"

DrawObject::DrawObject(float x, float y, float z, float r, float g, float b): drawPos(x,y,z), color(r,g,b)
{}

OrthoObject::OrthoObject(float x, float y, float z, float r, float g, float b): DrawObject(x,y,z,r,g,b) {
	EnableDraw();
}
OrthoObject::~OrthoObject() {
	DisableDraw();
}	
bool OrthoObject::operator<(const OrthoObject& o) const {
	return drawPos.z > o.drawPos.z; //Want this to go from largest value to smallest so that we draw back to front
}

ModelObject::ModelObject(float x, float y, float z, float r, float g, float b): DrawObject(x,y,z,r,g,b) {
	EnableDraw();
}
ModelObject::~ModelObject() {
	DisableDraw();
}

void OrthoObject::EnableDraw() {
	drawEnabled = true;
	DrawSystem::Instance().addOrthoObject(this);
}
void OrthoObject::DisableDraw() {
	drawEnabled = false;
	DrawSystem::Instance().removeOrthoObject(this);
}

void ModelObject::EnableDraw() {
	drawEnabled = true;
	DrawSystem::Instance().addModelObject(this);
}

void ModelObject::DisableDraw() {
	drawEnabled = false;
	DrawSystem::Instance().removeModelObject(this);
}

void DebugRect::draw(unsigned long) {
	glColor4d(color.r, color.g, color.b, color.a);
	
	glBegin(GL_LINE_LOOP);
		glVertex3d(drawPos.x, drawPos.y, drawPos.z);
		glVertex3d(drawPos.x, drawPos.y + dimensions.y,  drawPos.z);
		glVertex3d(drawPos.x+dimensions.x, drawPos.y + dimensions.y, drawPos.z);
		glVertex3d(drawPos.x+dimensions.x, drawPos.y, drawPos.z);
	glEnd();
}

void DebugDrawSpot::draw(unsigned long) {
	glColor4d(color.r, color.g, color.b, color.a);
	glTranslated(drawPos.x, drawPos.y, drawPos.z);
	
	glBegin(GL_QUADS);
		glVertex3d(-w, -w, 0);
		glVertex3d( w, -w, 0);
		glVertex3d( w,  w, 0);
		glVertex3d(-w,  w, 0);
		
		glVertex3d(-w, 0, -w);
		glVertex3d( w, 0, -w);
		glVertex3d( w, 0,  w);
		glVertex3d(-w, 0,  w);
		
		glVertex3d(0, -w, -w);
		glVertex3d(0,  w, -w);
		glVertex3d(0,  w,  w);
		glVertex3d(0, -w,  w);
	glEnd();
}

